package test.java.ufabc.edu.compiladores.javauino.analisadores.lexico;

import static main.java.ufabc.edu.compiladores.javauino.analisadores.lexico.enumx.Kind.EOF;
import static main.java.ufabc.edu.compiladores.javauino.analisadores.lexico.enumx.Kind.NUMBER;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

import main.java.ufabc.edu.compiladores.javauino.analisadores.lexico.domain.Scanner;
import main.java.ufabc.edu.compiladores.javauino.analisadores.lexico.domain.Token;
import main.java.ufabc.edu.compiladores.javauino.analisadores.lexico.enumx.Kind;

public class ScannerWithInput {

	private static final String MESSAGE = "Para execução do teste, é necessario passar o caminho do arquivo javuino a ser testado.";

	public static void main(String[] args) throws FileNotFoundException {
		if (args.length == 0) {
			throw new RuntimeException(MESSAGE);
		}
		File file = new File(args[0]);
		FileInputStream inputStrean = new FileInputStream(file);
		
		Reader reader = new InputStreamReader(inputStrean);
		Scanner.init(reader);
		Token token = null;
		int count = 1;
		do {
			token = Scanner.next();
			if(token.getKind().equals(Kind.IDENTIFIER)) {
				System.out.println("Token " + count + ": "+ token.getString() + " Linha: " + token.line + " Coluna: " + token.col);
			} else if(token.getKind().equals(NUMBER)) {
				System.out.println("Token " + count + ": "+ token.getVal() + " Linha: " + token.line + " Coluna: " + token.col);
			} else {
				System.out.println("Token " + count + ": "+ token.getKind().getValue() + " Linha: " + token.line + " Coluna: " + token.col);
			}
			count ++;
		} while(!token.getKind().equals(EOF));
		try {
			inputStrean.close();
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
